<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>发起请求</button>
    <h1>我是主页</h1>
    <script src="./Promise封装请求方式.js"></script>

    <script>
        const btn = document.querySelector('button')
        const h1 = document.querySelector('h1')
        btn.addEventListener('click', async function () {
            const res = await harryAjax({ method: 'GET', url: 'http://ajax-base-api-t.itheima.net/api/getbooks' })
            console.log(res);
        //接收所有请求，
        Promise.all([
            harryAjax({
                method: 'GET',
                url: 'http://ajax-base-api-t.itheima.net/api/getbooks'
            }),
            harryAjax({
                method: 'POST',
                data: {
                    bookname: 'promise.all',
                    author: '8',
                    publisher: 'chuanzhi'
                },
                url: 'http://ajax-base-api-t.itheima.net/api/addbook'
            })
        ])
            .then(res => {
                h1.innerHTML = '我不管，反正我是对的'
            })
            .catch(err => {
                h1.innerHTML = 404
            })
        })
    </script>
</body>

</html>